package com.shudai.largescreen.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.shudai.largescreen.mapper.DistributorMapper;
import com.shudai.largescreen.pojo.dto.UserDetailDto;
import com.shudai.largescreen.pojo.vo.*;
import com.shudai.largescreen.service.DistributorService;
import com.shudai.largescreen.util.DateQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import static com.shudai.largescreen.util.DateQuery.getYearStart;

@Service
@RequiredArgsConstructor
@Slf4j
public class DistributorServiceImpl implements DistributorService {

    private final DistributorMapper distributorMapper;

    @Override
    public AllCityAmount getAllCityAmount() {
        //总订单
        String orders = distributorMapper.findAllCityOrders();
        //总用户
        String customer = distributorMapper.findAllCityCustomer();
        AllCityAmount allCityAmount = new AllCityAmount();
        allCityAmount.setTotal(customer);
        allCityAmount.setFinish(Integer.valueOf(orders));
        return allCityAmount;
    }

    @Override
    public NumberRate getCityNumberRate(String province, String region, String time, String teamName) throws ParseException {
        NumberRate numberRate = new NumberRate();
        // 首先根据前端传来的时间区间，查询出区间中所有的月份；

        System.out.println("time时间: " + time);
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String startDate = null;
        String endDate = null;
        if (StringUtils.isEmpty(time)) {
            startDate = DateUtil.format(DateQuery.getCurrYearFirst(), format1);
            endDate = DateUtil.format(DateQuery.getCurrYearLast(), format1);

        }
        if (StringUtils.isNotEmpty(time)) {

            endDate = DateUtil.format(DateQuery.getYearLast(Integer.parseInt(time)), format1);
            startDate = DateUtil.format(DateQuery.getYearFirst(Integer.parseInt(time)), format1);

        }

        List<Date> lDate = DateQuery.getMonths(startDate, endDate);

        System.out.println("区间：");
        for (Date date : lDate) {
            System.out.println(date);
        }

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime startLocalTime = LocalDateTime.parse(startDate + "", df);
        LocalDateTime endLocalTime = LocalDateTime.parse(endDate + "", df);


        //查询客户数量
        List<NumberAmount> numberAmounts = distributorMapper.findCityNumber(province, region, startLocalTime, endLocalTime, teamName);


        if (CollectionUtils.isNotEmpty(numberAmounts)) {
            //总订单数
            long count = numberAmounts.stream().mapToInt(NumberAmount::getData).sum();
//        cityOrder.setSuccessOrder(count + "");
            numberRate.setTotal(count + "");
        } else {
            numberRate.setTotal(0 + "");
        }


        if (CollectionUtils.isEmpty(lDate)) {
            return null;
        }

        List<NumberAmount> experienceDayResList = new ArrayList<>(numberAmounts);

        for (Date date : lDate) {
            // 当前日期不存在则新增
            String dateStr = DateUtil.format(date, "yyyy-MM");
            // 进行匹配
            if (!experienceDayResList.stream().filter(item -> dateStr.equals(item.getName())).findAny().isPresent()) {
                NumberAmount experienceDayRes = NumberAmount.builder()
                        .name(dateStr)
                        .data(0)
                        .build();
                experienceDayResList.add(experienceDayRes);
            }
        }

        List<NumberAmount> collect = experienceDayResList.stream().sorted(Comparator.comparing(NumberAmount::getName)).collect(Collectors.toList());


        if (StringUtils.isEmpty(province) && StringUtils.isEmpty(region)) {
            numberRate.setArea("全国");
            numberRate.setDistrict("全国");
            numberRate.setChartData(collect);
        } else {
            if (StringUtils.isNotEmpty(teamName)) {
                numberRate.setArea(province + "-" + region + "-" + teamName);
            } else {
                numberRate.setArea(province + "-" + region);
            }

            numberRate.setDistrict(region);
            numberRate.setChartData(collect);

        }

        String moth = DateQuery.getMothStart().split(" ")[0].split("-")[1];

        if (Integer.parseInt(moth) >= 1) {

            BigDecimal successOrder = collect.get(Integer.parseInt(moth) - 1)
                    == null ? new BigDecimal(0) : new BigDecimal(collect.get(Integer.parseInt(moth)).getData());
            BigDecimal successOrder1 = collect.get(Integer.parseInt(moth) - 2)
                    == null ? new BigDecimal(0) : new BigDecimal(collect.get(Integer.parseInt(moth) - 2).getData());

            if (successOrder1.equals(new BigDecimal(0))) {
                numberRate.setIncRate(successOrder);
            }
            BigDecimal rate = new BigDecimal(0);
            if (!successOrder1.equals(new BigDecimal(0))) {
                rate = (successOrder.subtract(successOrder1)).divide(successOrder1, 2, RoundingMode.HALF_UP);

            }
            System.out.println("rate: " + rate);
            numberRate.setIncRate(rate);
        } else {
            numberRate.setIncRate(new BigDecimal(0));
        }


        for (int i = 0; i < numberRate.getChartData().size(); i++) {
            String[] s = numberRate.getChartData().get(i).getName().split("-");
            numberRate.getChartData().get(i).setName(s[1].replaceFirst("^0*", "") + "月");
        }

        return numberRate;
    }


    @Override
    public List<TopSaleAchievement> getTopSaleAchievement(String district, String city, String teamName,String startTime) {

        LocalDate someStart = null;
        LocalDate someEnd = null;
        LocalDate someStartLast = null;
        LocalDate someEndLast = null;
        if (StringUtils.isEmpty(startTime)) {
            String mothNow =  (DateTime.now() + "").split(" ")[0].split("-")[0] +(DateTime.now() + "").split(" ")[0].split("-")[1];
            String mothLast =  (DateTime.now() + "").split(" ")[0].split("-")[0] + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1);
            //这月的
            someStart = DateQuery.getMothSomeStart(mothNow);
            someEnd = DateQuery.getMothSomeEnd(mothNow);
            //上月的
            someStartLast = DateQuery.getMothSomeStart(mothLast);
            someEndLast = DateQuery.getMothSomeEnd(mothLast);

        }


        if (StringUtils.isNotEmpty(startTime) && !startTime.substring(4).equals("01")){
            someStart = DateQuery.getMothSomeStart(startTime);
            someEnd = DateQuery.getMothSomeEnd(startTime);

            //上月的
            someStartLast = DateQuery.getMothSomeStart((Integer.parseInt(startTime)-1)+"");
            someEndLast = DateQuery.getMothSomeEnd((Integer.parseInt(startTime)-1)+"");
        }
        if (StringUtils.isNotEmpty(startTime) && startTime.substring(4).equals("01")){
            someStart = DateQuery.getMothSomeStart(startTime);
            someEnd = DateQuery.getMothSomeEnd(startTime);

            //上年的最后一个月的
            someStartLast = DateQuery.getMothSomeStart((Integer.parseInt(startTime)-89)+"");
            someEndLast = DateQuery.getMothSomeEnd((Integer.parseInt(startTime)-89)+"");
        }

        //本周第一天
//        String weekStart = DateQuery.getMothStart();
//        String weekStart = "2022-05-10 00:00:00";

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime startLocalTime = LocalDateTime.parse(someStart+" 00:00:00", df);
        LocalDateTime endLocalTime = LocalDateTime.parse(someEnd+" 00:00:00", df);

        LocalDateTime startLocalTimeLast = LocalDateTime.parse(someStartLast+" 00:00:00", df);
        LocalDateTime endLocalTimeLast = LocalDateTime.parse(someEndLast+" 00:00:00", df);

        //查询销售人员姓名，id和地址
        List<UserDetailDto> userDital = distributorMapper.findUserDital(district, city, teamName);

        if (CollectionUtils.isNotEmpty(userDital)) {
            //根据id 查询用户的本周总金额
            List<Long> collect = userDital.stream().map(UserDetailDto::getId).collect(Collectors.toList());
            List<UserDetailDto> userDetileMoney = distributorMapper.findAllMoneyWeek(collect, startLocalTime,endLocalTime);
            //查询本周下单金额
            List<UserDetailDto> userDetileMoneyAll = distributorMapper.findAllMoneyWeekAll(collect, startLocalTime,endLocalTime);

            //查询新增客户
            List<UserDetailDto> customerNew = distributorMapper.findCustomerNew(collect,  startLocalTime,endLocalTime);

            //查询总用户数
            List<UserDetailDto> allCustomer = distributorMapper.findAllCustomer(collect);


//        //查询最近七天下单人 上个月下单的人
//            LocalDateTime startMonth = LocalDateTime.parse(DateQuery.getMothStartLast(), df);
//            LocalDateTime endMonth = LocalDateTime.parse(DateQuery.getMothEndLast(), df);

            List<UserDetailDto> orderWeek = distributorMapper.findOrderWeek(collect, startLocalTimeLast, endLocalTimeLast);

            if (CollectionUtils.isNotEmpty(orderWeek)) {
                //直接查
                List<Long> userRecordIds = orderWeek.stream().map(UserDetailDto::getUserRecordId).collect(Collectors.toList());
                List<Long> userIds = orderWeek.stream().map(UserDetailDto::getId).collect(Collectors.toList());
                //上月下单，这月返单
                List<UserDetailDto> userRate = distributorMapper.findUserRate(userRecordIds, startLocalTime,endLocalTime);
                Map<Long, Long> userRateMap = userRate.stream().filter(x -> x.getTotal() > 0).collect(Collectors.groupingBy(UserDetailDto::getId, Collectors.counting()));

                //总订单
                List<UserDetailDto> orderWeekTatal = distributorMapper.findOrderWeekTatal(userIds, startLocalTime,endLocalTime);
                Map<Long, Long> userTotalMap = orderWeekTatal.stream().filter(x -> x.getTotal() > 0).collect(Collectors.toMap(UserDetailDto::getId, UserDetailDto::getTotal));

                List<TopSaleAchievement> topSaleStaticVos = new ArrayList<>();

                //本周下单用户id
//        pinCrownMapper.findAllUserRecordWeek(localTime);

                for (UserDetailDto userDetile : userDital) {
                    TopSaleAchievement topSaleStaticVo = new TopSaleAchievement();
                    topSaleStaticVo.setCustomerTotal(0);
                    topSaleStaticVo.setCustomerNew("0");
                    topSaleStaticVo.setTransactionAmount(0.00);
                    topSaleStaticVo.setAvatarUrl("无");
                    topSaleStaticVo.setId(userDetile.getId());
                    topSaleStaticVo.setOrderAmount(0.00);
                    topSaleStaticVo.setRateReturn(new BigDecimal(0));
                    topSaleStaticVo.setSalesman(userDetile.getUserName());
//            topSaleStaticVo.setTeamName(userDetile.getProvince() + "-" + userDetile.getCity() + "-" + userDetile.getDistrict());
                    topSaleStaticVo.setTeamName(userDetile.getName());

                    //总金额 userDetileMoneyAll
                    for (UserDetailDto detile : userDetileMoney) {
                        if (userDetile.getId().equals(detile.getId())) {
                            topSaleStaticVo.setTransactionAmount(detile.getOrderAmountWeek());
                        }
                    }
                    for (UserDetailDto detile : userDetileMoneyAll) {
                        if (userDetile.getId().equals(detile.getId())) {
                            topSaleStaticVo.setOrderAmount(detile.getOrderAmountWeekAll());
                        }
                    }

                    //新增用户数
                    for (UserDetailDto detile : customerNew) {
                        if (userDetile.getId().equals(detile.getId())) {
                            topSaleStaticVo.setCustomerNew(detile.getCustomerWeek());
                        }
                    }
                    //总用户数
                    for (UserDetailDto detile : allCustomer) {
                        if (userDetile.getId().equals(detile.getId())) {
                            topSaleStaticVo.setCustomerTotal(detile.getCustomerAll());
                        }
                    }
                    //返单
                    Long rate = userRateMap.get(userDetile.getId());
                    Long total = userTotalMap.get(userDetile.getId());


                    if (total != null && rate != null) {
                        topSaleStaticVo.setRateReturn(new BigDecimal(rate).divide(new BigDecimal(total), 2, RoundingMode.HALF_UP));
                    }
                    if (rate==null){
                        topSaleStaticVo.setRepurchaseNumber(0L);
                    }else {
                        topSaleStaticVo.setRepurchaseNumber(rate);
                    }

                    topSaleStaticVos.add(topSaleStaticVo);
                }
                List<TopSaleAchievement> collect1 = topSaleStaticVos.stream().sorted(Comparator.comparingDouble(TopSaleAchievement::getTransactionAmount).reversed()).collect(Collectors.toList());

                for (int i = 0; i < collect1.size(); i++) {
                    collect1.get(i).setTop((i + 1));
                }
                return collect1;
            } else {
                List<TopSaleAchievement> topSaleStaticVos = new ArrayList<>();
                //查询总用户数
//                List<UserDetailDto> allCustomes = distributorMapper.findAllCustomer(collect);

                for (UserDetailDto userDetile : userDital) {
                    TopSaleAchievement topSaleStaticVo = new TopSaleAchievement();
                    topSaleStaticVo.setCustomerTotal(0);
                    topSaleStaticVo.setCustomerNew("0");
                    topSaleStaticVo.setTransactionAmount(0.00);
                    topSaleStaticVo.setAvatarUrl("无");
                    topSaleStaticVo.setId(userDetile.getId());
                    topSaleStaticVo.setOrderAmount(0.00);
                    topSaleStaticVo.setRateReturn(new BigDecimal(0));
                    topSaleStaticVo.setSalesman(userDetile.getUserName());
//            topSaleStaticVo.setTeamName(userDetile.getProvince() + "-" + userDetile.getCity() + "-" + userDetile.getDistrict());
                    topSaleStaticVo.setTeamName(userDetile.getName());

                    topSaleStaticVo.setTransactionAmount(0.00);
                    //总金额 userDetileMoneyAll

                    topSaleStaticVo.setOrderAmount(0.00);
                    //新增用户数
                    topSaleStaticVo.setCustomerNew(0 + "");

                    //总用户数
                    for (UserDetailDto detile : allCustomer) {
                        if (userDetile.getId().equals(detile.getId())) {
                            topSaleStaticVo.setCustomerTotal(detile.getCustomerAll());
                        }
                    }

                    //返单
                    topSaleStaticVo.setRateReturn(new BigDecimal(0));


                    topSaleStaticVos.add(topSaleStaticVo);
                }
                List<TopSaleAchievement> collect1 = topSaleStaticVos.stream().sorted(Comparator.comparingDouble(TopSaleAchievement::getCustomerTotal).reversed()).collect(Collectors.toList());

                for (int i = 0; i < collect1.size(); i++) {
                    collect1.get(i).setTop((i + 1));
                }
                return collect1;

            }
        }
        return null;
    }


    @Override
    public CityRate getCityOrderRate(String city, String district) {
        //本周第一天
//        String weekStart = "2022-08-10 00:00:00";

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");


        LocalDateTime startM = LocalDateTime.parse(DateQuery.getMothStart(), df);
        LocalDateTime endM = LocalDateTime.parse(DateQuery.getMothEnd(), df);
        LocalDateTime startMonth = LocalDateTime.parse(DateQuery.getMothStartLast(), df);
        LocalDateTime endMonth = LocalDateTime.parse(DateQuery.getMothEndLast(), df);
        //根据城市查询销售 得到用户id 上月下单
        List<CityRate> cityRates = distributorMapper.findCityOrderRecord(city, district, startMonth, endMonth);

        if (CollectionUtils.isNotEmpty(cityRates)) {
            //查之前有没有下过单
            List<Long> userRecordIds = cityRates.stream().map(CityRate::getUserRecordId).collect(Collectors.toList());
            List<UserDetailDto> userRate = distributorMapper.findUserRate(userRecordIds, startM,endM);
//      Map<Long, Long> userRateMap = userRate.stream().filter(x -> x.getTotal() > 0).collect(Collectors.groupingBy(UserDetailDto::getUserRecordId, Collectors.counting()));

            //查询城市下单量
            //总订单
            Integer orderWeekTatal = distributorMapper.findOrderWeekCity(city, district, startM);
            System.out.println("城市下单： " + orderWeekTatal);
            long count = userRate.stream().filter(x -> x.getTotal() > 0).mapToLong(UserDetailDto::getTotal).count();
            System.out.println("返单人次数： " + count);

            CityRate cityRate = new CityRate();
            if (StringUtils.isEmpty(city) && StringUtils.isEmpty(district)) {
                cityRate.setArea("全国");
                cityRate.setDistrict("全国");
            } else {
                if (StringUtils.isNotEmpty(district)) {
                    cityRate.setArea(district);
                } else {
                    cityRate.setArea(city);
                }

                cityRate.setDistrict(district);
            }

            if (orderWeekTatal != null && orderWeekTatal != 0) {
                cityRate.setChartData(new BigDecimal(count).divide(new BigDecimal(orderWeekTatal), 2, RoundingMode.HALF_UP));
                cityRate.setAreaValue(new BigDecimal(count).divide(new BigDecimal(orderWeekTatal), 2, RoundingMode.HALF_UP));
            } else {
                cityRate.setChartData(new BigDecimal(0));
                cityRate.setAreaValue(new BigDecimal(0));
            }
            return cityRate;
        }else {
            CityRate cityRate = new CityRate();
            if (StringUtils.isEmpty(district)){
                cityRate.setDistrict(city);
                cityRate.setArea(city);
            }else {
                cityRate.setDistrict(district);
                cityRate.setArea(district);
            }

            cityRate.setChartData(new BigDecimal(0));
            cityRate.setAreaValue(new BigDecimal(0));
            return cityRate;
        }
    }

    @Override
    public CityOrderRate getCityOrderIncrease(String province, String region, String time, String teamName) throws ParseException {
        // 首先根据前端传来的时间区间，查询出区间中所有的月份；
        String startDate = null;
        String endDate = null;

        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        if (StringUtils.isEmpty(time)) {
            startDate = DateUtil.format(DateQuery.getCurrYearFirst(), format1);
            endDate = DateUtil.format(DateQuery.getCurrYearLast(), format1);

        }
        if (StringUtils.isNotEmpty(time)) {

            endDate = DateUtil.format(DateQuery.getYearLast(Integer.parseInt(time)), format1);
            startDate = DateUtil.format(DateQuery.getYearFirst(Integer.parseInt(time)), format1);

        }


        List<Date> lDate = DateQuery.getMonths(startDate, endDate);

        System.out.println("区间：");
        for (Date date : lDate) {
            System.out.println(date);
        }

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime startLocalTime = LocalDateTime.parse(startDate, df);
        LocalDateTime endLocalTime = LocalDateTime.parse(endDate, df);


        System.out.println(province + " 地区：还不即可  " + region);
        //查询每月数量
        List<CityOrderMoth> cityOrderRate = distributorMapper.findCityOrderRate(province, region, startLocalTime, endLocalTime, teamName);

        CityOrderRate cityOrder = new CityOrderRate();

        //订单总数
        if (CollectionUtils.isNotEmpty(cityOrderRate)) {
            //总订单数
            int sum = cityOrderRate.stream().mapToInt(CityOrderMoth::getData).sum();
            cityOrder.setFinish(sum + "");
        } else {
            cityOrder.setFinish(0 + "");
        }

        List<CityOrderMoth> experienceDayResList = new ArrayList<>(cityOrderRate);

        if (StringUtils.isEmpty(province) && StringUtils.isEmpty(region)) {
            cityOrder.setDistrict("全国");
            cityOrder.setArea("全国");
        } else {
            if (StringUtils.isNotEmpty(region)) {
                if (StringUtils.isNotEmpty(teamName)) {
                    cityOrder.setArea(region + "-" + teamName);
                } else {
                    cityOrder.setArea(region);
                }
            } else {
                cityOrder.setArea(province);
            }


            cityOrder.setDistrict(region);
        }

        for (Date date : lDate) {
            // 当前日期不存在则新增
            String dateStr = DateUtil.format(date, "yyyy-MM");
            // 进行匹配
            if (!experienceDayResList.stream().filter(item -> dateStr.equals(item.getName())).findAny().isPresent()) {
                CityOrderMoth experienceDayRes = CityOrderMoth.builder()
                        .name(dateStr)
                        .data(0)
                        .area(province)
                        .district(region)
                        .build();
                experienceDayResList.add(experienceDayRes);
            }
        }
        List<CityOrderMoth> collect = experienceDayResList.stream().sorted(Comparator.comparing(CityOrderMoth::getName)).collect(Collectors.toList());
        cityOrder.setChartData(collect);


        //已下单数
        String orderCity = distributorMapper.findCityOrders(province, region, startLocalTime, endLocalTime, teamName);
        cityOrder.setTotal(orderCity);

        //取消数量
        String orderCityFalse = distributorMapper.findCityOrdersFalse(province, region, startLocalTime, endLocalTime, teamName);
        cityOrder.setOrderFalse(orderCityFalse == null ? "0" : orderCityFalse);


        String moth = DateQuery.getMothStart().split(" ")[0].split("-")[1];

        if (Integer.parseInt(moth) >= 1) {

            BigDecimal successOrder = collect.get(Integer.parseInt(moth) - 1)
                    == null ? new BigDecimal(0) : new BigDecimal(collect.get(Integer.parseInt(moth) - 1).getData());
            BigDecimal successOrder1 = collect.get(Integer.parseInt(moth) - 2)
                    == null ? new BigDecimal(0) : new BigDecimal(collect.get(Integer.parseInt(moth) - 2).getData());

            System.out.println("successOrder1 : " + successOrder1);
            if (successOrder1.equals(new BigDecimal(0))) {
                cityOrder.setIncRate(successOrder);
            } else {
                BigDecimal rate = (successOrder.subtract(successOrder1)).divide(successOrder1, 2, RoundingMode.HALF_UP);
                System.out.println("rate: " + rate);
                cityOrder.setIncRate(rate);
            }

        } else {
            BigDecimal bigDecimal = new BigDecimal(0);
            cityOrder.setIncRate(bigDecimal);
        }


        for (int i = 0; i < cityOrder.getChartData().size(); i++) {
            String[] s = cityOrder.getChartData().get(i).getName().split("-");
            cityOrder.getChartData().get(i).setName(s[1].replaceFirst("^0*", "") + "月");
        }


        return cityOrder;
    }

    @Override
    public CityOrder getCityOrder(String province, String region, String targetOrder) {
        if (StringUtils.isEmpty(targetOrder)) {
            targetOrder = "10000";
        }

        String mothStart = DateQuery.getMothStart();
//        String mothStart = "2020-10-10 00:00:00";

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime LocalTime = LocalDateTime.parse(mothStart, df);

        System.out.println(mothStart);
        List<CityOrder> cityOrder1 = distributorMapper.getCityOrder(province, region, LocalTime);

        CityOrder cityOrder = new CityOrder();


        cityOrder.setAreaValue(cityOrder1.stream().mapToInt(CityOrder::getAreaValue).sum());
        cityOrder.setFinish(cityOrder1.stream().mapToInt(CityOrder::getAreaValue).sum());
        if (StringUtils.isEmpty(province) && StringUtils.isEmpty(region)) {
            cityOrder.setArea("全国");
            cityOrder.setDistrict("全国");
        } else {
            if (StringUtils.isNotEmpty(region)) {
                cityOrder.setArea(region);
            } else {
                cityOrder.setArea(province);
            }

            cityOrder.setDistrict(region);
        }
        cityOrder.setChartData(new BigDecimal(cityOrder.getAreaValue()).divide(BigDecimal.valueOf(Long.parseLong(targetOrder)), 2, RoundingMode.HALF_UP));
        cityOrder.setTarget(targetOrder);
        return cityOrder;

    }
}
